package com.dayu.gulimall;


public class ChocolateBoiler {

    private boolean empty;
    private boolean boiled;
    private volatile static ChocolateBoiler instance;

    private ChocolateBoiler(){
        empty=true;
        boiled=false;
        System.out.println("当前线程： "+Thread.currentThread().getName());
    }

    public static ChocolateBoiler getInstance(){
        if (instance==null){
            synchronized (ChocolateBoiler.class){
                if (instance==null){
                    instance=new ChocolateBoiler();
                }
            }
        }
        return instance;
    }

    public void fill(){
        if (empty){
            empty=false;
            boiled=false;
            System.out.println(Thread.currentThread().getName()+"填充原料。。");
        }
    }

    public void drain(){
        if (!empty && boiled){
            //排出煮沸的巧克力
            empty=true;
            boiled=false;
            System.out.println(Thread.currentThread().getName()+"排出成品");
        }
    }

    public void boil(){
        if (!empty&& !boiled){
            System.out.println(Thread.currentThread().getName()+"煮沸");
            boiled=true;
        }
    }


    public boolean isEmpty() {
        return empty;
    }

    public boolean isBoiled() {
        return boiled;
    }


}


